<?php
/**
 *    折扣商品管理控制器
 */
class Discount_activityApp extends BackendApp
{
    var $_discount_activity;
    var $_discount_goods;
    var $_goods;
    var $_goodsSpec;
    var $_store_detail_mod;

    function __construct()
    {
        $this->GoodsApp();
    }

    function GoodsApp()
    {
        parent::BackendApp();
        $this->_goods =& m('goods');
        $this->_goodsSpec =& m('goodsspec');
        $this->_discount_activity =& m('discount_activity');
        $this->_discount_goods =& m('discount_goods');
        $this->_store_detail_mod = &m("store_detail");
    }

    //折扣商品列表
    function index(){
        $conditions = '';
        // 处理分页
        $page = $this->_get_page(10);
        $list = $this->_discount_activity->find(array(
            'conditions'=>"1=1".$conditions,
            'limit' => $page['limit'],
            'count' => true,
        ));
        $page['item_count'] = $this->_discount_activity->getCount();
        $this->assign('filtered', $conditions ? 1 : 0); //是否有查询条件
        $this->_format_page($page);
        $this->assign('page_info', $page);
        $this->assign('list', $list);
        // 引入前端资源
        $this->import_resource(array('script' => 'inline_edit.js,jquery.ui/jquery.ui.js,jquery.ui/i18n/' . i18n_code() . '.js',
            'style' => 'jquery.ui/themes/ui-lightness/jquery.ui.css'));
        // 显示模板
        $this->display('discount_activity.list.html');
    }
    //添加
    function add(){
        if(IS_POST){
            $data = $_POST;
            if(!$data['goods_id']){
                $this->show_message('请选择商品！');
                return false;
            }
            if(!$data['start_time']){
                $this->show_message('请选择开始时间！');
                return false;
            }
            if(!$data['end_time']){
                $this->show_message('请填写结束时间！');
                return false;
            }
            $start_time = strtotime($data['start_time']);
            $end_time = strtotime($data['end_time']);
            if($start_time >= $end_time){
                $this->show_message('开始时间不可以大于等于结束时间！');
                return false;
            }
            //先匹配开始时间是否在已有活动中存在
            $conditions = "start_time <".$start_time.' AND end_time >'.$start_time;
            $is_start = $this->_discount_activity->get(array("conditions"=>$conditions));
            if($is_start){
                $this->show_message('开始时间已重复！');
                return false;
            }
            //然后匹配结束时间是否在已有活动中存在
            $conditions_end = "start_time <".$end_time." AND end_time >".$end_time;
            $is_end = $this->_discount_activity->get(array("conditions"=>"$conditions_end"));
            if($is_end){
                $this->show_message('结束时间已重复！');
                return false;
            }
            $arr = array(
                'start_time'  => $start_time,
                'end_time'    => $end_time,
                'remark'      => $data['remark']
            );
            //添加新的折扣活动
            if (!$discount_id = $this->_discount_activity->add($arr)) {  //获取discount_id
                $this->show_warning($this->_discount_activity->get_error());
                return;
            } else {
                $this->admin_log("新增折扣活动", 1);
            }
            $count = count($data['goods_arr']);
            $keye = array_keys($data['goodsSorts']);
            for($i=0;$i<$count;$i++){
                for($j=0;$j<count($data['goodsSorts']);$j++){
                    if($data['goods_arr'][$i] == $keye[$j]){
                        $sortOrders[$i] = $data['goodsSorts'][$keye[$j]];
                    }
                }
                $specInfo = $this->_goodsSpec->get(array("conditions"=>"spec_id = ".$data['spec'][$i]));
                $tax_price[$i] = 0.00;
                if($specInfo['spec_3value'] != 25){
                    $tax_price[$i] = sprintf("%.2f",$data['price'][$i] * $data['consolidated_tax'][$i]);
                    $tax_price[$i] = $data['price'][$i] * $data['consolidated_tax'][$i];
                }
            }

            //更新商品列表信息
            foreach($data['goods_arr'] as $k=>$v){
                $newArr['discount_id']   = $discount_id;
                $newArr['goods_id']      = $v;
                $newArr['sort_order']    = $sortOrders[$k];
                $newArr['discount_price']= $data['price'][$k];
                $newArr['spec_id']       = $data['spec'][$k];
                $newArr['discount_tax_price']       = $tax_price[$k];
                $this->_discount_goods->add($newArr);
            }
            $this->show_message('添加成功', 'back_list', 'index.php?app=discount_activity',
                'continue_add', 'index.php?app=discount_activity&amp;act=add'
            );
        }else{
            $this->display('discount_activity.form.html');
        }
    }

    //导出
    function discount_excel(){
        $discount_id = $_GET['discount_id'];
        $info = array_values($this->_discount_goods->find(array("conditions"=>"discount_id = ".$discount_id,'fields'=>"discount_price,goods_id,spec_id")));

        foreach($info as $k=>$v){
            $info[$k]['spu'] = $this->_goods->get(array("conditions"=>"goods_id = ".$v['goods_id'],"fields"=>"sku"));
            $info[$k]['sku'] = $this->_goodsSpec->get(array("conditions"=>"spec_id = ".$v['spec_id'],"fields"=>"sku"));
        }
        $statlist['headertitle'] = array('ID','spu', 'sku', 'price');
        $to_charset = (CHARSET == 'utf-8') ? substr(LANG, 0, 2) == 'sc' ? 'gbk' : 'big5' : '';
        $num = 0;
        $data[$num]['ID'] = $statlist['headertitle'][0];
        $data[$num]['spu'] = $statlist['headertitle'][1];
        $data[$num]['sku'] = $statlist['headertitle'][2];
        $data[$num]['discount_price'] = $statlist['headertitle'][3];

        foreach($info as $k=>$v){
            $data[$num+1]['ID'] = $k+1;
            $data[$num+1]['spu'] = $v['spu']['sku'];
            $data[$num+1]['sku'] = $v['sku']['sku'];
            $data[$num+1]['discount_price'] = $v['discount_price'];
            $num++;
        }
        if(!empty($data)){
            $this->export_to_csv($data, date('Y-m-d H:i:s').'活动导出', $to_charset);
            exit();
        }
        $this->show_message('暂无数据');

    }
    //编辑
    function view(){
        $discount_id = $_GET['discount_id']?$_GET['discount_id']:'';
        if(!$discount_id){
            $this->show_message('参数错误！');
            return false;
        }
        $find_data = $this->_discount_activity->get(array("conditions"=>"discount_id = ".$discount_id));
        if(!$find_data){
            $this->show_message('数据错误！');
            return false;
        }
        if(IS_POST){

            $data = $_POST;
            if(!$data['goods_id']){
                $this->show_message('请选择商品！');
                return false;
            }
            if(!$data['start_time']){
                $this->show_message('请选择开始时间！');
                return false;
            }
            if(!$data['end_time']){
                $this->show_message('请填写结束时间！');
                return false;
            }
            $start_time = strtotime($data['start_time']);
            $end_time = strtotime($data['end_time']);
            if($start_time >= $end_time){
                $this->show_message('开始时间不可以大于等于结束时间！');
                return false;
            }
            //先匹配开始时间是否在已有活动中存在
            $conditions = "start_time <".$start_time.' AND end_time >'.$start_time.' AND discount_id <>'.$discount_id;
            $is_start = $this->_discount_activity->get(array("conditions"=>$conditions));
            if($is_start){
                $this->show_message('开始时间已重复！');
                return false;
            }
            //然后匹配结束时间是否在已有活动中存在
            $conditions_end = "start_time <".$end_time." AND end_time >".$end_time.' AND discount_id <> '.$discount_id;
            $is_end = $this->_discount_activity->get(array("conditions"=>"$conditions_end"));
            if($is_end){
                $this->show_message('结束时间已重复！');
                return false;
            }
            $arr = array(
                'start_time'  => $start_time,
                'end_time'    => $end_time,
                'remark'      => $data['remark']
            );
            //添加新的折扣活动
            $this->_discount_activity->edit($discount_id,$arr);  //获取discount_id

            $sql = "Delete from ecm_discount_goods where discount_id = ".$discount_id;
            $this->_discount_goods->db->query($sql);;

            $count = count($data['goods_arr']);
            $keye = array_keys($data['goodsSorts']);
            for($i=0;$i<$count;$i++){
                for($j=0;$j<count($data['goodsSorts']);$j++){
                    if($data['goods_arr'][$i] == $keye[$j]){
                        $sortOrders[$i] = $data['goodsSorts'][$keye[$j]];
                    }
                }
                $specInfo = $this->_goodsSpec->get(array("conditions"=>"spec_id = ".$data['spec'][$i]));
                $tax_price[$i] = 0.00;
                if($specInfo['spec_3value'] != 25){
                    $tax_price[$i] = sprintf("%.2f",$data['price'][$i] * $data['consolidated_tax'][$i]);
                }
            }

            //更新商品列表信息
            foreach($data['goods_arr'] as $k=>$v){
                $newArr['discount_id']   = $discount_id;
                $newArr['goods_id']      = $v;
                $newArr['sort_order']    = $sortOrders[$k];
                $newArr['discount_price']= $data['price'][$k];
                $newArr['spec_id']       = $data['spec'][$k];
                $newArr['discount_tax_price']       = $tax_price[$k];
                $this->_discount_goods->add($newArr);
            }
            $this->show_message('保存成功', 'back_list', 'index.php?app=discount_activity',
                '再次编辑', 'index.php?app=discount_activity&amp;act=view&discount_id='.$discount_id
            );
        }else{

            $goods_id = array_values($this->_discount_goods->find(array("conditions"=>"discount_id = ".$discount_id)));
            $goods_ids = '';
            foreach($goods_id as $k=>$v){
                if($k == 0){
                    $goods_ids = $v['goods_id'];
                }else{
                    $goods_ids .= ','.$v['goods_id'];
                }
            }
            $goods_list = $this->_discount_activity->getGoods($goods_ids);
            foreach($goods_list as $key=>$value){
                $sortInfo = $this->_discount_goods->get(array("conditions"=>"discount_id = ".$discount_id.' AND goods_id = '.$value['goods_id']));
                $goods_list[$key]['sort_order'] = $sortInfo['sort_order'];
                foreach($value['specInfo'] as $k=>$v){
                    $goodsInfo = $this->_discount_goods->get(array("conditions"=>"discount_id = ".$discount_id.' AND spec_id = '.$v['spec_id']));
                    $goods_list[$key]['specInfo'][$k]['discount_price'] = $goodsInfo['discount_price'];
                }
            }
            $this->assign('ids',$goods_ids);
            $this->assign('info',$goods_list);
            $this->assign('data',$find_data);
            $this->display('discount_activity.form.html');
        }
    }

    //删除
    function drop(){
        $discount_id = isset($_GET['discount_id']) ? intval($_GET['discount_id']) : 0;
        if (!$discount_id)
        {
            $this->show_warning('no_such_banner');
            return;
        }
        $info = $this->_discount_activity->get(intval($discount_id));

        if (!$this->_discount_activity->drop($discount_id)) {    //删除
            $this->show_warning($this->_discount_activity->get_error());
            return;
        }else{
            $sqldelete = 'Delete from ecm_discount_goods where discount_id = '.$discount_id;
            $this->_discount_activity->db->query($sqldelete);
        }
        $this->show_message('删除成功');
    }
    //选择活动商品
    function choicesGoods(){
        $conditions = $this->_get_query_conditions(array(
            array(
                'field' => 'goods_name',
                'equal' => 'like',
            ),
            array(
                'field' => 'store_name',
                'equal' => 'like',
            ),
            array(
                'field' => 'brand',
                'equal' => 'like',
            ),

        ));
        // 分类
        $cate_id = empty($_GET['cate_id']) ? 0 : intval($_GET['cate_id']);
        if ($cate_id > 0)
        {
            $cate_mod =& bm('gcategory');
            $cate_ids = $cate_mod->get_descendant_ids($cate_id);
            $conditions .= " AND cate_id" . db_create_in($cate_ids);
        }

        //更新排序
        if (isset($_GET['sort']) && isset($_GET['order']))
        {
            $sort  = strtolower(trim($_GET['sort']));
            $order = strtolower(trim($_GET['order']));
            if (!in_array($order,array('asc','desc')))
            {
                $sort  = 'goods_id';
                $order = 'desc';
            }
        }
        elseif($_GET['sort'] == 4){ //今日上新
            $sort = 'add_time';
            $order = 'desc';
        }else {
            $sort  = 'goods_id';
            $order = 'desc';
        }
        $page = $this->_get_page(60);
        //断码

        //查询断码价
        $spec_model = & m('goodsspec');

        if($_GET['cut_off']){
            $sql = "select 
            ecm_storestock.stock_name, 
            ecm_goods.goods_id, 
            group_concat(ecm_goods_spec.spec_2) as spec2, 
            case when locate(',',group_concat(ecm_goods_spec.spec_2)) > 0 then 0 else 1 end as is_unique,
            ecm_goods_spec.stock
        from 
            ecm_goods, 
            ecm_goods_spec, 
            ecm_storestock 
        where 
            ecm_storestock.storestock_id = ecm_goods_spec.spec_3value and ecm_goods.goods_id = ecm_goods_spec.goods_id and ecm_goods_spec.stock > 0
        group by 
            ecm_goods.goods_id 
        having is_unique > 0";
            $db = &db('goods');
            $res_sql = $db->getall($sql);
            $conditions .= " AND g.goods_id" . db_create_in(array_column($res_sql,'goods_id'));
        }

        $storeStock = & m('storestock');

        //年代
        if($_GET['times']){
            $times = explode(',',$_GET['times']);
            $sql_time = '';
            foreach($times as $k=>$times_item){
                if($k == 0){
                    $sql_time = 'g.times like '."'%".trim($times_item)."%'";
                }else{
                    $sql_time .= ' OR g.times like '."'%".trim($times_item)."%'";
                }
            }
            $conditions .= " AND (".$sql_time.")";
        }

        //仓库 、国际码
        if($_GET['storestock_id'] || $_GET['international_code']){
            if($_GET['storestock_id'] && is_numeric($_GET['storestock_id'])){
                $where['conditions'] = 'spec_3value = '.$_GET['storestock_id'];
                $this->assign('storestock_id',$_GET['storestock_id']);
            }
            if($_GET['international_code']){
                $where['conditions'] = 'international_code like '."'%".$_GET['international_code']."%'";
                $this->assign('international_code',$_GET['international_code']);
            }
            if($_GET['storestock_id'] && is_numeric($_GET['storestock_id']) && $_GET['international_code']){
                $where['conditions'] = 'spec_3value = '.$_GET['storestock_id'].' AND international_code like'."'%".$_GET['international_code']."%'";
                $this->assign('storestock_id',$_GET['storestock_id']);
                $this->assign('international_code',$_GET['international_code']);
            }
            $this->_goodsSpecInfo = $this->_goodsSpec->find($where);
            $specList = array_values($this->_goodsSpecInfo);
            $ids = '';
            if(!empty($specList)){
                foreach($specList as $k=>$v){
                    if($k == 0){
                        $ids = $v['goods_id'];
                    }else{
                        $ids .= ','.$v['goods_id'];
                    }
                }
                $conditions .= ' AND g.goods_id IN ('.$ids.')';
            }else{
                $conditions .= ' AND g.goods_id = 0 ';
            }
        }

        //是否上下架
        if($_GET['closed']){
            if($_GET['closed'] == 2){
                $closed = 0;
            }else{
                $closed = 1;
            }
            $conditions .= ' AND g.closed = '.$closed;
            $this->assign('closed',$_GET['closed']);
        }

        //库存数筛选
        if($_GET['count_from'] || $_GET['count_to']){
            if($_GET['count_from'] && !$_GET['count_to']){
                $count_from = $_GET['count_from'];
                $sql = "select * from (select sum(stock) as ccaa,goods_id from ecm_goods_spec group by goods_id ) as ccaa where ccaa >=$count_from";
            }elseif($_GET['count_to'] && !$_GET['count_from']){
                $count_to = $_GET['count_to'];
                $sql = "select * from (select sum(stock) as ccaa,goods_id from ecm_goods_spec group by goods_id ) as ccaa where ccaa <=$count_to";
            }else{
                $count_to = $_GET['count_to'];
                $count_from = $_GET['count_from'];
                $sql = "select * from (select sum(stock) as ccaa,goods_id from ecm_goods_spec group by goods_id ) as ccaa where (ccaa >=$count_from and ccaa<=$count_to)";
            }
            $info = $this->_goodsSpec->db->query($sql);
            while ($chat = $this->_goodsSpec->db->fetchRow($info)) {
                $chat_listOld[] = $chat;
            }
            if(!empty($chat_listOld)){
                $wish_ids = '';
                foreach($chat_listOld as $k=>$v){
                    if($k == 0){
                        $wish_ids = $v['goods_id'];
                    }else{
                        $wish_ids .= ','.$v['goods_id'];
                    }
                }
                $conditions .= " AND g.goods_id in (".$wish_ids.")";
            }
            $this->assign('count_from',$_GET['count_from']);
            $this->assign('count_to',$_GET['count_to']);
        }

        //价格筛选
        if($_GET['price_from'] || $_GET['price_to']){
            if($_GET['price_from'] && !$_GET['price_to']){
                $price_from = $_GET['price_from'];
                $sql = "select * from (select price as ccaa,goods_id from ecm_goods_spec group by goods_id ) as ccaa where ccaa >=$price_from";
            }elseif($_GET['price_to'] && !$_GET['price_from']){
                $price_to = $_GET['price_to'];
                $sql = "select * from (select price as ccaa,goods_id from ecm_goods_spec group by goods_id ) as ccaa where ccaa <=$price_to";
            }else{
                $price_to = $_GET['price_to'];
                $price_from = $_GET['price_from'];
                $sql = "select * from (select price as ccaa,goods_id from ecm_goods_spec group by goods_id ) as ccaa where (ccaa >=$price_from and ccaa<=$price_to)";
            }
            $info_price = $this->_goodsSpec->db->query($sql);
            while ($chat_price = $this->_goodsSpec->db->fetchRow($info_price)) {
                $chat_listOld_price[] = $chat_price;
            }
            if(!empty($chat_listOld_price)){
                $wish_ids_price = '';
                foreach($chat_listOld_price as $k=>$v){
                    if($k == 0){
                        $wish_ids_price = $v['goods_id'];
                    }else{
                        $wish_ids_price .= ','.$v['goods_id'];
                    }
                }
                $conditions .= " AND g.goods_id in (".$wish_ids_price.")";
            }
            $this->assign('price_from',$_GET['price_from']);
            $this->assign('price_to',$_GET['price_to']);
        }

        $goods_list = $this->_goods->get_list(array(
            'conditions' => "1 = 1" . $conditions,
            'count' => true,
            'order' => "$sort $order",
            'limit' => $page['limit'],
        ));
        $my_tax = &m("my_tax");
        foreach ($goods_list as $key => $goods)
        {
            $goods_list[$key]['cate_name'] = $this->_goods->format_cate_name($goods['cate_name']);
            $goods_list[$key]['default_image']  =   WEB_PHOTO_SRC . "/" . $goods['default_image'];
            $goods_list[$key]['times']  =   $goods['times'];
            $taxInfo = $my_tax->get(array("conditions"=>"tax_id =".$goods['tax_id']));
            $goods_list[$key]['consolidated_tax'] = $taxInfo['consolidated_tax'];
//            //单独查询规格表中的标价
            $retult = $this->_goodsSpec->find(array('conditions'=>"goods_id = ".$key));
            if(!empty($retult)) {
                $str['domestic_price'] = 0;
                $str['domestic_discount'] = '无';
                $str['hong_kong_price'] = 0;
                $str['hong_kong_discount'] = '无';

                //声明一个库存数
                $inventory = $this->_store_detail_mod->get_count($goods['sku']);
                $in_array = array();
                $stock_array = array();
                foreach ($retult as $k => $v) {
                    if ($v['spec_3value'] != 26) {                    //国内仓标价
                        $str['domestic_price'] = $v['price'];
                        if($goods['market_price'] && $goods['market_price'] != 0.00){
                            $str['domestic_discount'] = sprintf('%.2f', $v['price'] / $goods['market_price']) . '折';//国内仓折扣
                        }else{
                            $str['domestic_discount'] = 0 . '折';//国内仓折扣
                        }
                    }
                    if ($v['spec_3value'] == 26) {
                        $str['hong_kong_price'] = $v['price'];
                        if($v['price'] && $v['price'] != 0.00 && $goods['market_price'] != 0.00){
                            $str['hong_kong_discount'] = sprintf('%.2f', $v['price'] / $goods['market_price']) . '折';//香港折扣
                        }else{
                            $str['hong_kong_discount'] = 0 . '折';//香港折扣
                        }
                    }
                }
                $res_ss = $this->_goodsSpec->getSpecStockInfo($key);
                foreach ($res_ss as $k => $v) {
                    $v['international_code'] && !in_array($v['international_code'],$in_array)  ?  $in_array[] = $v['international_code'] : NULL;
                    $v['stock_name'] && !in_array($v['stock_name'],$stock_array) ? $stock_array[] = $v['stock_name'] : NULL;
                    $res_ss[$k]['image'] = WEB_PHOTO_SRC  . "/" . $v['spec_1'];
                }
                $in_array ? $goods_list[$key]['international_code'] = implode('<br>',$in_array) : NULL;
                $stock_array ? $goods_list[$key]['stock_name'] = implode('<br>',$stock_array) : NULL;
                $goods_list[$key]['domestic_price'] = $str['domestic_price'];
                $goods_list[$key]['domestic_discount'] = $str['domestic_discount'];
                $goods_list[$key]['hong_kong_price'] = $str['hong_kong_price'];
                $goods_list[$key]['hong_kong_discount'] = $str['hong_kong_discount'];
                //总库存
                $goods_list[$key]['total_inventory'] = $inventory?$inventory:0;

            }
            $goods_list[$key]['specInfo'] = $res_ss;
        }
        $this->assign('goods_list', $goods_list);

        $page['item_count'] = $this->_goods->getCount();
        $this->_format_page($page);
        $this->assign('page_info', $page);

        // 第一级分类
        $cate_mod =& bm('gcategory', array('_store_id' => 0));
        $this->assign('gcategories', $cate_mod->get_options(0, true));

        //仓库
        $this->assign('storeStock',$storeStock->get_options());

        $this->assign('cut_off', $_GET['cut_off']? 1 : 0); //是否有查询条件
        $this->import_resource(array('script' => 'mlselection.js,inline_edit.js '));
        $this->display('discount_activity.iframe.html');
    }
    //ajax请求添加到页面的商品列表
    function post(){
        $goods_id = $_POST['goods_id'];
        if(!$goods_id){
            $code = -1;
            $msg = '数据错误';
            echo json_encode(array('code'=>$code,'msg'=>$msg));
            exit();
        }
        $goods_list = $this->_discount_activity->getGoods($goods_id);
        echo json_encode(array("code"=>1,'msg'=>'','data'=>$goods_list));
        exit();
    }

    // 今日秒杀活动的配置项  包括分享到朋友圈图片以及前端分享折扣活动小程序页面的小图
    function setting(){
        if(IS_POST){
            $file = $_FILES;
            if($file['killmoments_image']){
                $this->_upload($file,'killmoments_image');
            }
            if($file['killfront_image']){
                $this->_upload($file,'killfront_image');
            }
            $this->show_message('保存成功！');
        }else{
            $data = &m("limited_setting")->get(array('limited_id'=>1));
            $info['killmoments_image'] = WEB_PHOTO_SRC.'/'.$data['killmoments_image'];
            $info['killfront_image'] = WEB_PHOTO_SRC.'/'.$data['killfront_image'];
            $this->assign('info',$info);
            $this->display('discount_activity.setting.html');
        }
    }

    function _upload($file,$str){
        require_once '../includes/aliyunOss/samples/Common.php';
        $image = $file[$str];
        $imageName = date("YmdHis", time()) . rand(1000,10000);
        $path = 'data/files/mall/discount_activity/'.$str;

        if ($image['error'] == UPLOAD_ERR_NO_FILE) { // 没有文件被上传
            return '';
        }
        import('uploader.lib');             //导入上传类
        $uploader = new Uploader();
        $uploader->allowed_type(IMAGE_FILE_TYPE); //限制文件类型
        $uploader->addFile($_FILES[$str]); //上传logo
        if (!$uploader->file_info()) {
            $this->show_warning($uploader->get_error(), 'go_back', 'index.php?app=discount_activity&amp;act=setting');
            return false;
        }
        /* 指定保存位置的根目录 */
        $uploader->root_dir(ROOT_PATH);
        if (!$file_path = $uploader->save($path,$imageName)) {   //保存到指定目录，并以指定文件名$ad_id存储
            $this->show_message('上传文件失败！');
            return false;
        }
        $ossClient = new \common;
        $r = $ossClient->putObjectFile('../'.$file_path,$file_path);
        if(!$r['info'] || $r['info']['http_code'] != 200){
            $this->show_message('上传oss失败！');
            return false;
        }
        $save = &m("limited_setting")->edit(1,array($str=>$file_path));
        unlink('../'.$file_path);
        $this->show_message('上传成功！');
        return false;
    }


}